#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author   : Moty
# @Time     : 2024/10/18 22:39
# @File     : kc16_44.py
# @Project  : CSPT
def parse_44_Offline_Card_Data_Sync(body):
    # 获取下发卡个数
    num_cards = int(body[14:16], 16)

    # 初始化数据字典
    data = {
        "桩编号": f"{body[0:14]}({body[0:14]})",
        "下发卡个数": f"{num_cards}({body[14:16]})",
    }

    # 动态解析每个卡的逻辑卡号和物理卡号
    for i in range(1, num_cards + 1):
        start_index_logic = 16 + (i - 1) * 16
        end_index_logic = start_index_logic + 8
        start_index_physical = end_index_logic
        end_index_physical = start_index_physical + 8

        # 逻辑卡号
        data[
            f"第 {i} 个卡逻辑卡号"] = f"{body[start_index_logic:end_index_logic]}({body[start_index_logic:end_index_logic]})"
        # 物理卡号
        data[
            f"第 {i} 个卡物理卡号"] = f"{body[start_index_physical:end_index_physical]}({body[start_index_physical:end_index_physical]})"

    # 格式化输出
    formatted_data = ""
    for key, value in data.items():
        formatted_data += f"{key}: {value}\n"

    return formatted_data


__all__ = ['parse_44_Offline_Card_Data_Sync']

